<?php
class User extends Controller {
	public function html() {
		$mUser = new User_model();
		$currUser = $mUser->currUser();
		if(!$currUser) header('Location:/auth/login?backurl='.urlencode('/rbac/role/'));
		
		$roleId = $this->get('roleId', 'int');
		if(!$roleId) header('Location:/rbac/role/');
		
		$data = array();
		$tpl = 'rbac/role/user.html';
		
		$mRole = new Role_model();
		$mRbac = new Rbac_model();
		
		$data['role'] = $mRole->roleById($roleId);
		
		//获取节点信息
		$data['users'] = $mUser->userAll();
		$data['selected'] = $mRbac->role2userAll($roleId);
		
		$this->display($data, $tpl);
	}
	public function json() {
		$roleId = $this->post('roleId', 'int');
		$uid = $this->post('uid', 'arr');
		
		if(!$roleId) $this->displayJSON(array('status' => -1, 'message' => '未知角色ID'));
		
		$mRbac = new Rbac_model();
		$result = $mRbac->role2user($roleId, $uid);
		if($result) $this->displayJSON(array('status' => 0, 'message' => '分配用户成功'));
		else $this->displayJSON(array('status' => -2, 'message' => '分配用户失败'));
	}
}